package gui.gui2d.highLevelPanels;

import gui.gui2d.TestAnimatedPane.Animate;
import java.awt.*;
import java.awt.event.MouseListener;
import javax.swing.*;
import world.pieces.*;

public class SelecterPiecePanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	SelecterPieceJLabel queenLabel ;
	SelecterPieceJLabel rockLabel ;
	SelecterPieceJLabel bishopLabel ;
	SelecterPieceJLabel knightlabel ;
	SelecterPieceJLabel pownlabel ;
	Rectangle from = new Rectangle(-200,200 , 100, 500);
	Rectangle to = new Rectangle(0,200 , 100, 500);
	private JPanel panel;
	public SelecterPiecePanel() {
		setLayout(null);
		panel = new JPanel();
		panel.setBackground(new Color(50,23,23,100));
		panel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

	}

	public void addPanel(utility.Color c){
		panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
		loadPiece(c);
		add(panel);
		Animate animate = new Animate(panel, from, to);
		animate.start();
	}

	private void loadPiece(utility.Color c){
		
		Queen q= new Queen(c);
		queenLabel = new SelecterPieceJLabel(new ImageIcon(q.get2DPath()),1,c);

		Rook r= new Rook(c);
		rockLabel= new SelecterPieceJLabel( new ImageIcon(r.get2DPath()),2,c);

		Bishop b = new Bishop(c);
		bishopLabel= new SelecterPieceJLabel( new ImageIcon(b.get2DPath()),3,c);

		Knight k = new Knight(c);
		knightlabel= new SelecterPieceJLabel(new ImageIcon(k.get2DPath()),4,c);

		Pown p = new Pown(c);
		pownlabel=new SelecterPieceJLabel(new ImageIcon(p.get2DPath()),5,c);

		panel.add(queenLabel);
		panel.add(rockLabel);
		panel.add(bishopLabel);
		panel.add(knightlabel);
		panel.add(pownlabel);


	}

	public void addListener(MouseListener ml){
		System.out.println("aggiungo gli ascoltatori");
		queenLabel.addMouseListener(ml);
		rockLabel.addMouseListener(ml);
		bishopLabel.addMouseListener(ml);
		knightlabel.addMouseListener(ml);
		pownlabel.addMouseListener(ml);
	}


	public void removePanel(){
		Animate animate = new Animate(panel, to, from);
		animate.start();
	}



	@Override
	public Dimension getPreferredSize() {
		return new Dimension(200, 200);
	}

}
